package marek.barak.classes;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
import java.util.Map;

import marek.barak.exceptions.InvalidActionValueException;
import marek.barak.interfaces.ActionsDAO;

public class ActionHddDAO implements ActionsDAO {
	private List<Action> actions;
	private ConnectionActions connection;
	
	public void setActionTime(int i,Map<Integer,Integer> time) throws IndexOutOfBoundsException, InvalidActionValueException, FileNotFoundException, IOException{
		getAction(i).setTime(time);
		connection.saveAllActions(actions);
	}
	
	public Action getAction(int i)throws IndexOutOfBoundsException{
		return actions.get(i);
	}
	public ActionHddDAO() throws FileNotFoundException, IOException, ClassNotFoundException{
		connection = ConnectionActions.getInstance();
		actions = connection.loadAllActions();
	}
	@Override
	public List<Action> getActions() {
		return actions;
	}
	public void setActions(List<Action> actions) throws FileNotFoundException, IOException{
		connection.saveAllActions(actions);
	}
	public Map<Integer,Integer> getActionTime(Action a){
		return a.getTime();
	}
	public void addAction(Action a) throws InvalidActionValueException, FileNotFoundException, IOException{
		if(actions.contains(a))
			throw new InvalidActionValueException("Action already exits");
		else{
			System.out.println(a.getTime().size());
			actions.add(a);
			connection.saveAllActions(actions);
		}
	}
	public ActionMade getInstanceOfDoneAction(int amounth) {
		
		return null;
		
	}
	public void removeSelectedAction(Action a)throws InvalidActionValueException, FileNotFoundException, IOException{
		if(actions.contains(a)){
			actions.remove(a);
			connection.saveAllActions(actions);
		}else
			throw new InvalidActionValueException("Action doest exits you cant remove it");
	}

}
